package com.contact.util;

import com.contact.util.util.collections.MapsMap;
import com.contact.util.util.collections.Utils;


/**
 * This utility is an Enum Registry applicable to the enums that implement
 * QuickCode. It's main use is to be able to retrieve the correct quick code by
 * code and class.
 * 
 */
public final class QuickCodeRegistry {
    
    private static MapsMap<Class<? extends QuickCode>, String, QuickCode> map = Utils.newLinkedMapsMap();

    private QuickCodeRegistry() {
        //singleton
    }

    public static <T extends QuickCode> void register(String code, T value) {
        Class<? extends QuickCode> clazz = value.getClass();
        map.put(clazz, code, value);
    }

    @SuppressWarnings("unchecked")
    public static <T extends QuickCode> T fromCode(Class<T> clazz, String code) {
        return (T) map.get(clazz, code);
    }

}
